<html>
<head>
    <title>省市县三级联动</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <script>
        //创建ajax引擎
        function getXmlHttpObject(){
            var xmlHttpRequest;
            //不同浏览器获取对象xmlhttprequest 对象方法不一样
            if(window.ActiveXObject){
                xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
            }else{
                xmlHttpRequest=new XMLHttpRequest();
            }
            return xmlHttpRequest;
        }
        var myXmlHttpRequest;

        function getCities(){
            myXmlHttpRequest=getXmlHttpObject();
            if(myXmlHttpRequest){
                var url="/ajax/li2/showCitiesPro.php";//post
                var data = "province="+$('sheng').value;

                myXmlHttpRequest.open("post",url,true);
                myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                myXmlHttpRequest.onreadystatechange=chuli;
                myXmlHttpRequest.send(data);
            }
        }

        function chuli(){
            if(myXmlHttpRequest.readyState==4){
                if(myXmlHttpRequest.status==200){
                    var cities=myXmlHttpRequest.responseXML.getElementsByTagName("city");
                    $('city').length=0;
                    var myOption=document.createElement("option");
                    myOption.innerText="--城市--";
                    $('city').appendChild(myOption);
                    //遍历并取值
                    for(var i=0;i<cities.length;i++){
                        var city_name=cities[i].childNodes[0].nodeValue;
                        //window.alert(city_name);
                        var myOption=document.createElement("option");
                        myOption.value=city_name;
                        myOption.innerText=city_name;
                        //添加到
                        $('city').appendChild(myOption);
                    }
                }
            }
        }

        //在这里写一个函数
        function $(id){
            return document.getElementById(id);
        }
    </script>
</head>
<body>
<select id="sheng" onchange="getCities();">
    <option value="">---省---</option>
    <option value="zhejiang">浙江</option>
    <option value="jiangsu">江苏</option>
</select>
<select id="city">
    <option value="">--城市--</option>
</select>
<select id="county">
    <option value="">--县城--</option>
</select>
</body>
</html>